package org.stragma.apply.util

import org.kiama.rewriting.Rewriter.{fail,id,rulefs,Strategy,Term}

import org.stragma.apply.signatures.Apply._

/*
 * This object consists of some of the math function used in Apply
 */
object LogicalOperators {
	/*
	 * Port of ltS strategy from Stratego
	 */
	def ltS = rulefs {
		case (arg0 : String, arg1 : String) =>	if (arg0 < arg1) id	else fail
		case (Int(arg0),Int(arg1)) => if (arg0.toInt < arg1.toInt) id else fail
	}
	
	/*
	 * Port of leqS strategy from Stratego
	 */
	def leqS = rulefs {
		case (arg0 : String, arg1 : String) =>	if (arg0 <= arg1) id else fail
		case (Int(arg0),Int(arg1)) => if (arg0.toInt <= arg1.toInt) id else fail
	}
	
	/*
	 * Port of leqS strategy from Stratego
	 */
	def gtS = rulefs {
		case (arg0 : String, arg1 : String) =>	if (arg0 > arg1) id else fail
		case (Int(arg0),Int(arg1)) => if (arg0.toInt > arg1.toInt) id else fail
	}
	
	/*
	 * Port of leqS strategy from Stratego
	 */
	def geqS = rulefs {
		case (arg0 : String, arg1 : String) =>	if (arg0 >= arg1) id else fail
		case (Int(arg0),Int(arg1)) => if (arg0.toInt >= arg1.toInt) id else fail
	}
	
	/*
	 * Port of eq strategy from Stratego
	 */
	def eqS = rulefs {
		case (arg0 : String, arg1 : String) =>	if (arg0 == arg1) id else fail
		case (Int(arg0),Int(arg1)) => if (arg0.toInt == arg1.toInt) id else fail
	}
	
	/*
	 * Port of neq strategy from Stratego
	 */
	def neq = rulefs {
		case (arg0 : String, arg1 : String) =>	if (arg0 != arg1) id else fail
		case (Int(arg0),Int(arg1)) => if (arg0.toInt != arg1.toInt) id else fail
	}
}